﻿$(function() {
    VoiceCreate.init();
    Utils.textBoxsOnEnter(VoiceCreate.Create);
});


var VoiceCreate =
{
    init: function() {
        $("#btnSave").click(this.Create);
        $("#chtWord").focus();
        $(document).keyup(function(e) {
            if (e.keyCode == 27) {
                var needConfirm = utility.hasFormData();
                window.parent.utility.closePopUpUrlConfirm(needConfirm);
            }
        });
    },
    Create: function() {
        var chtWord = $("#chtWord");
        var descript = $("#descript");
        var example = $("#example");
        var voiceWord = $("#voiceWord");
        var categorySn = $("#categorySn");

        targetFunction = (parent != undefined) ? parent.ErrorHelper : ErrorHelper;
        targetFunction.checkNonNull(chtWord, m.Err1101);
        targetFunction.checkNonNull(descript, m.Err1102);
        targetFunction.checkNonNull(example, m.Err1103);
        targetFunction.checkNonNull(voiceWord, m.Err1104);
        if (!targetFunction.popUpIfError()) {
            var param = {
                chtWord: chtWord.val()
                , descript: descript.val()
                , example: example.val()
                , voiceWord: voiceWord.val()
                , categorySn: categorySn.val()
            };
            var cb = Utils.getCBfunction('Voice');
            var ecb = function() { $("#chtWord").focus(); };
            window.parent.utility.ajaxext("VoiceService/Create", param, "POST", cb, ecb);
        }
    }
};
